import { DefaultStage } from '../default-stage';
import { Sky } from './sky';
import { Sea } from './sea';
import { RawAssetsName, RawAssetsUrl } from '../../raw-asset-info';
import { Helper } from 'babylon-lib/tool/helper';
import { Vector3 } from '@babylonjs/core/Maths/math.vector';


class LandscapeManager {

    public static readonly wind = new Vector3(1, 1, 1).normalize();

    private static _stage: DefaultStage;

    public static initialize(stage: DefaultStage): void {
        this._stage = stage;
        this.initializeLand();
        Sky.initialize(stage);
        Sea.initialize(stage);
    }

    private static initializeLand(): void {
        const loader = this._stage.loader(this._stage.mainScene);

        let model = loader.getMeshTaskInfo(RawAssetsUrl.modelCheng)!;
        model.loadedMeshes?.forEach(m => m.position.y = 1e6);
        model = loader.getMeshTaskInfo(RawAssetsUrl.modelZhen)!;
        model.loadedMeshes?.forEach(m => m.position.y = 1e6);
        model = loader.getMeshTaskInfo(RawAssetsUrl.modelGuan)!;
        model.loadedMeshes?.forEach(m => m.position.y = 1e6);
        model = loader.getMeshTaskInfo(RawAssetsUrl.modelCun)!;
        model.loadedMeshes?.forEach(m => m.position.y = 1e6);

        model = loader.getMeshTaskInfo(RawAssetsUrl.modelDixing)!;
        model?.loadedMeshes?.forEach(mesh => {
            mesh.isPickable = false;
        });
        const mainland = Helper.nodeInArray(RawAssetsName.mainland, model?.loadedMeshes!, undefined, true);
        mainland?.position.set(0, -4, 0);
    }

}


export { LandscapeManager };